Conversation
| def to_dict(self): | ||
| goal_as_dict = {} | ||
| goal_as_dict["id"] = self.goal_id | ||
| goal_as_dict["title"] = self.title | ||
|
|
||
|
|
||
| return goal_as_dict No newline at end of file |
| description = task_data["description"] | ||
| ) | ||
|
|
||
| return new_task No newline at end of file |
| try: | ||
| new_goal = Goal(title=request_body["title"]) | ||
|
|
||
| except: | ||
| abort(make_response({ | ||
| "details": "Invalid data" |
There was a problem hiding this comment.
Like we validated models, could we also make a general function that validates request bodies? Here's an example:
def validate_request_body(request_body, keys):
for key in keys:
if not request_body.get(key):
abort(make_response({
'Invalid Data': f'missing key: {key}'
}, 400))
return TrueWe can pass in the request_body and a list of strings that are keys and then check to see if those keys are present.
There was a problem hiding this comment.
Now we can have error handling and request body validation across all our routes more easily.
| for goal in goals: | ||
| goals_response.append( | ||
| goal.to_dict() | ||
| ) |
There was a problem hiding this comment.
Nice utilization of your .to_dict() helper method! ⭐️
| for task in request_body["task_ids"]: | ||
| task = validate_model(Task, task) | ||
| tasks_list.append(task) | ||
| task.goal_id = goal.goal_id |
| for task in goal.tasks: | ||
| tasks_list.append({ | ||
| "id" : task.task_id, | ||
| "goal_id" : task.goal_id, | ||
| "title" : task.title, | ||
| "description" : task.description, | ||
| "is_complete" : False | ||
| }) |
There was a problem hiding this comment.
Well done! I have a question for you, do you think that this loop and the logic within could be moved to into the Goal class?
| if sort_query == "asc": | ||
| tasks = Task.query.order_by(Task.title.asc()).all() | ||
| elif sort_query == "desc": | ||
| tasks = Task.query.order_by(Task.title.desc()).all() | ||
| else: | ||
| tasks = Task.query.all() |
|
|
||
| return jsonify(tasks_response) | ||
|
|
||
| def validate_model(cls, model_id): |
There was a problem hiding this comment.
Make sure your helper functions are in a place that's easy to find
|
|
||
| task = validate_model(Task, task_id) | ||
|
|
||
| send_slack_message(task.title) |
There was a problem hiding this comment.
So, right now your route sends a message to slack saying that the task has been completed, before the task is marked complete. But what happens if your can't actually commit the change, your code will send out a false positive. You typically will want to send alerts like this after all your other logic has ran.
|
|
||
| return make_response({ | ||
| "details": f'{Task.__name__} {task_id} "{task.title}" successfully deleted' | ||
| }), 200 No newline at end of file |
There was a problem hiding this comment.
Well done on this project Maz, I didn't have much to comment on and that is a good thing! Keep up the good work! Really looking forward to what you create in the frontend! Please feel free to reach out if you have any questions about the feedback that I left! ✨💫🤭
No description provided.